
// out vec4 gl_FragColor;
// in vec2 gl_FragCoord;

//定义使用绘图API
#ifdef GL_ES
//决定精度
precision mediump float;
#endif

//常数
#define PI 3.1415926535
#define PIXEL.05
#define AA 2

//变量

//鼠标
uniform vec2 u_mouse;   
uniform vec2 u_resolution;
uniform float u_time;

//画布
vec2 FixUV(vec2 coord,float num){
    //画布原点移动到中央  并且不随外部画布拉伸
    //默认以短轴为基准 num=1.0
    vec2 uv=
        num*(2.*coord.xy-u_resolution)/
        min(u_resolution.x,u_resolution.y);
    return uv;
}

float sdfCircle(in vec2 p,float r){
    return length(p)-r;
}

void main(){
    
    vec2 uv=FixUV(gl_FragCoord.xy,2.);
    vec3 color=vec3(.5);
    
    //绘制圆
    float d=sdfCircle(uv,.7);
    //处理图面
    color=1.-sign(d)*vec3(.4,.5,.6);
    color*=1.-exp(-3.*abs(d));
    color*=.8+.1*sin(120.*abs(d));
    color=mix(color,vec3(1.),smoothstep(.005,.004,abs(d)));
    
    // if(u_mouse.button ){ }
    //鼠标动作
    vec2 m=FixUV(u_mouse.xy,2.);
    float mdis=sdfCircle(m,.7);
    mdis=abs(mdis);
    //可动园
    color=mix(color,vec3(.9216,.6039,.0902),
    smoothstep(.02,.01,abs(length(uv-m)-mdis)));
    //可动园的点
    color=mix(color,vec3(.902,.5176,.0824),
    smoothstep(.05,.03,abs(length(uv-m))) );
    // color *=vec3(u_mouse.button,1.,2.);
    // if(u_mouse.y>0.1){

    // }

    gl_FragColor=vec4(color,1.); 

}